package com.jackson.spring.aopxml;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;


public class LogingAspectj {

	public void beforeMethod(JoinPoint joinpoint){
		String methodname = joinpoint.getSignature().getName();
		System.out.println("the mothod begin" +methodname +" begin  with "+Arrays.asList(joinpoint.getArgs()));
	}
	
	public void afterMethod(JoinPoint joinpoint){
		String methodname = joinpoint.getSignature().getName();
		System.out.println("the mothod " +methodname +" end  with ");
	}
	
	public void afterReturnMethod(JoinPoint joinpoint,Object result1){
		String methodname = joinpoint.getSignature().getName();
		System.out.println("the mothod " +methodname +" @AfterReturning  with result "+result1);
	}
	
	public void afterThrowingMethod(JoinPoint joinpoint,Exception e){
		String methodname = joinpoint.getSignature().getName();
		System.out.println("the mothod " +methodname +"  @AfterThrowing with   "+e);
	}
	
	public Object aroundMethod(ProceedingJoinPoint pjp){
		 Object result = null;
		 String methodName =  pjp.getSignature().getName();
		 try {
			 // 前置通知
			 System.out.println(" aroundMethod the mothod " +methodName +" begin with "+Arrays.asList(pjp.getArgs()));
			 result = pjp.proceed();
			 //后置返回通知
			 System.out.println("the mothod " +methodName +" @AfterReturning  with result "+result);
		} catch (Throwable e) {
			e.printStackTrace();
			//异常通知
			System.out.println("the mothod " +methodName +"  @AfterThrowing with   "+e);
		}
		 //后置通知
		 System.out.println("the mothod " +methodName +" end  with ");
		return result;
	}
}
